package com.shop.dingdongshoppingapi.controller;

import com.shop.dingdongshoppingapi.dto.UserAddDto;
import com.shop.dingdongshoppingapi.dto.UserFindDto;
import com.shop.dingdongshoppingapi.dto.UserLoginDto;
import com.shop.dingdongshoppingapi.service.intf.UserService;
import com.shop.dingdongshoppingapi.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/user/")
@Api("用户注册登录接口")
@CrossOrigin
public class UserController {
	@Resource
	private UserService service;

	@GetMapping("checkphone.do")
	@ApiOperation("手机号验证是否注册过")
	public R checkphone(String phone){
		return service.checkPhone(phone);
	}

	@PostMapping("loginbyname.do")
	@ApiOperation("通过用户名登录")
	public R loginByName(@RequestBody UserLoginDto dto){
		return service.loginByName(dto);
	}

	@PostMapping("loginbyphone.do")
	@ApiOperation("通过验证码登录")
	public R loginByPhone(@RequestBody  UserLoginDto dto){
		return service.loginByPhone(dto);
	}

	@PostMapping("findpass.do")
	@ApiOperation("忘记密码")
	public R findpass(@RequestBody UserFindDto dto){
		return service.findPass(dto);
	}

	@GetMapping("logout.do")
	@ApiOperation("退出")
	public R logout(@RequestHeader Integer ddstoken){
		return service.loginOut(ddstoken);
//		return service.loginOut(token);
	}

	@PostMapping("register.do")
	@ApiOperation("注册功能")
	public R register(@RequestBody UserAddDto user){
		return service.register(user);
	}
}
